<template>
  <view class="main-container" :style="cssVars">
    <!-- 视频流区域 -->
    <view class="video-container" @touchstart="handleVideoTouch" @touchmove="handleVideoZoom"
      @click="showControlsWithDelay" @mousemove="showControlsWithDelay" @touchmove.stop="showControlsWithDelay">
      <!-- 离线状态提示 -->
      <view class="offline-overlay" v-if="!isConnected">
        <text class="offline-text">请检查网络连接</text>
      </view>
      <video v-if="isConnected" id="mainVideo" class="video-stream" :src="videoUrl" autoplay loop muted
        :controls="false" object-fit="cover"></video>

      <!-- 顶部状态栏 -->
      <view class="status-bar">
        <view class="status-item settings-icon" @click="toggleSettingsPanel">
          <image src="/static/icons/settings.svg" mode="aspectFit" />
        </view>
        <view class="status-item connection-status" :class="{ 'connected': isConnected }">
          <image src="/static/icons/signal.svg" mode="aspectFit" />
        </view>
      </view>

      <!-- 设置面板 -->
      <view class="modal-overlay" v-if="showSettingsPanel"></view>
      <view class="settings-panel" :class="{ 'show': showSettingsPanel }">
        <view class="panel-header">
          <text>{{ currentSettingsSection }}设置</text>
          <view class="close-btn" @click="toggleSettingsPanel">
            <text>×</text>
          </view>
        </view>
        <view class="panel-content">
          <view class="settings-section" v-if="currentSettingsSection === '云台相机' && isConnected">

          </view>
          <view class="settings-section" v-if="currentSettingsSection === '四合一' && isConnected">
            <view class="setting-item">
              <text>报警灯开关</text>
              <view class="alarm-light-controls">
                <switch :checked="alarmLight.enabled" @change="toggleAlarmLight" class="custom-switch" />
              </view>
            </view>
            <view class="setting-item">
              <text>报警灯模式</text>
              <view class="alarm-light-controls radio-group">
                <view class="radio-btn" :class="{ 'active': alarmLight.mode === 'normal' }"
                  @click="changeAlarmMode('normal')">
                  <text>正常</text>
                </view>
                <view class="radio-btn" :class="{ 'active': alarmLight.mode === 'fast' }"
                  @click="changeAlarmMode('fast')">
                  <text>快速</text>
                </view>
                <view class="radio-btn" :class="{ 'active': alarmLight.mode === 'slow' }"
                  @click="changeAlarmMode('slow')">
                  <text>慢速</text>
                </view>
              </view>
            </view>
            <view class="setting-item">
              <text class="section-title">广播内容</text>
              <view class="broadcast-controls">
                <view @click="addBroadcast" class="icon-btn add">
                  <image src="/static/icons/add.svg" mode="aspectFit" />
                </view>
              </view>
            </view>
            <view class="broadcast-list">
              <view v-for="item in broadcastList" :key="item.id" class="broadcast-item"
                :class="{ 'selected': selectedBroadcast === item.id }" @click="selectBroadcast(item.id)">
                <view class="broadcast-info">
                  <text class="broadcast-content">{{ item.content }}</text>
                </view>
                <view class="broadcast-actions">
                  <view @click.stop="editBroadcast(item)" class="icon-btn edit">
                    <image src="/static/icons/edit.svg" mode="aspectFit" />
                  </view>
                  <view @click.stop="deleteBroadcast(item.id)" class="icon-btn delete">
                    <image src="/static/icons/delete.svg" mode="aspectFit" />
                  </view>
                </view>
              </view>
            </view>
          </view>
          <view class="settings-section" v-if="currentSettingsSection === '机器狗' && isConnected">
            <view class="setting-item">
              <text>控制模式</text>
              <view class="robot-mode-controls radio-group">
                <view class="radio-btn" :class="{ 'active': robotMode === 'auto' }" @click="changeRobotMode('auto')">
                  <text>自动</text>
                </view>
                <view class="radio-btn" :class="{ 'active': robotMode === 'manual' }"
                  @click="changeRobotMode('manual')">
                  <text>手动</text>
                </view>
              </view>
            </view>
          </view>
          <view class="settings-section" v-if="currentSettingsSection === '系统'">
            <view class="setting-item">
              <text>服务器地址</text>
              <input type="text" v-model="serverConfig.url" placeholder="请输入服务器地址" @input="saveServerConfig" />
            </view>
            <view class="setting-item">
              <text>服务器端口</text>
              <input type="text" v-model="serverConfig.port" placeholder="请输入端口号" @input="saveServerConfig" />
            </view>
          </view>
        </view>
        <view class="panel-footer" v-if="isConnected">
          <view class="section-btn" :class="{ active: currentSettingsSection === '云台相机' }"
            @click="switchSettingsSection('云台相机')">
            <text>云台相机</text>
          </view>
          <view class="section-btn" :class="{ active: currentSettingsSection === '四合一' }"
            @click="switchSettingsSection('四合一')">
            <text>四合一</text>
          </view>
          <view class="section-btn" :class="{ active: currentSettingsSection === '机器狗' }"
            @click="switchSettingsSection('机器狗')">
            <text>机器狗</text>
          </view>
          <view class="section-btn" :class="{ active: currentSettingsSection === '系统' }"
            @click="switchSettingsSection('系统')">
            <text>系统</text>
          </view>
        </view>
      </view>

      <!-- 功能按钮组 -->
      <view class="camera-functions" :class="{ 'v-show': showControls && isConnected }">
        <view class="function-btn" @click="isConnected && toggleFeature('colorCamera')"
          :class="{ 'active': featureEnabled.colorCamera, 'disabled': !isConnected }">
          <image src="/static/icons/camera-color.svg" mode="aspectFit" />
          <text>彩色相机</text>
        </view>
        <view class="function-btn" @click="toggleFeature('bwCamera')" :class="{ 'active': featureEnabled.bwCamera }">
          <image src="/static/icons/camera-bw.svg" mode="aspectFit" />
          <text>黑白相机</text>
        </view>
        <view class="function-btn" @click="toggleFeature('tempMeasure')"
          :class="{ 'active': featureEnabled.tempMeasure }">
          <image src="/static/icons/temperature.svg" mode="aspectFit" />
          <text>测温功能</text>
        </view>
        <view class="function-btn" @click="toggleFeature('ptzCruise')" :class="{ 'active': featureEnabled.ptzCruise }">
          <image src="/static/icons/cruise.svg" mode="aspectFit" />
          <text>云台巡航</text>
        </view>
        <view class="function-btn" @click="toggleFeature('spotlight')" :class="{ 'active': featureEnabled.spotlight }">
          <image src="/static/icons/spotlight.svg" mode="aspectFit" />
          <text>探照灯</text>
        </view>
        <view class="function-btn" @click="toggleFeature('intercom')" :class="{ 'active': featureEnabled.intercom }">
          <image src="/static/icons/intercom.svg" mode="aspectFit" />
          <text>语音对讲</text>
        </view>
        <view class="function-btn" @click="toggleFeature('broadcast')" :class="{ 'active': featureEnabled.broadcast }">
          <image src="/static/icons/broadcast.svg" mode="aspectFit" />
          <text>广播</text>
        </view>
      </view>

      <!-- 控制 -->
      <view class="control-pad robot-control" :class="{ 'v-show': showControls && isConnected }">
        <view class="direction-pad">
          <view class="direction-row">
            <view class="direction-btn up" @touchstart="startRobotMove('up')" @touchend="stopRobotMove">
            </view>
          </view>
          <view class="direction-row">
            <view class="direction-btn left" @touchstart="startRobotMove('left')" @touchend="stopRobotMove">
            </view>
            <view class="direction-btn right" @touchstart="startRobotMove('right')" @touchend="stopRobotMove">
            </view>
          </view>
          <view class="direction-row">
            <view class="direction-btn down" @touchstart="startRobotMove('down')" @touchend="stopRobotMove">
            </view>
          </view>
        </view>
      </view>

      <!-- 摄像头控制 -->
      <view class="control-pad camera-control" :class="{ 'v-show': showControls && isConnected }">
        <view class="direction-pad">
          <view class="direction-row">
            <view class="direction-btn up" @touchstart="startCameraMove('up')" @touchend="stopCameraMove">
            </view>
          </view>
          <view class="direction-row">
            <view class="direction-btn left" @touchstart="startCameraMove('left')" @touchend="stopCameraMove">
            </view>
            <view class="direction-btn right" @touchstart="startCameraMove('right')" @touchend="stopCameraMove">
            </view>
          </view>
          <view class="direction-row">
            <view class="direction-btn down" @touchstart="startCameraMove('down')" @touchend="stopCameraMove">
            </view>
          </view>
        </view>
      </view>


    </view>
  </view>
</template>

<script>
import { request, updateHttpConfig } from '@/utils/request.js';
export default {
  computed: {
    cssVars() {
      return {
        '--camera-functions-bg': this.featureEnabled.bwCamera ? 'rgba(255, 255, 255, 0.4)' : 'rgba(0, 0, 0, 0.4)',
        '--camera-functions-shadow': this.featureEnabled.bwCamera ? '0 4px 6px rgba(255, 255, 255, 0.2)' : '0 4px 6px rgba(0, 0, 0, 0.2)',
        '--function-btn-bg': this.featureEnabled.bwCamera ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.5)',
        '--function-btn-border': this.featureEnabled.bwCamera ? 'rgba(0, 0, 0, 0.1)' : 'rgba(255, 255, 255, 0.1)',
        '--function-btn-hover-bg': this.featureEnabled.bwCamera ? 'rgba(255, 255, 255, 0.7)' : 'rgba(0, 0, 0, 0.7)',
        '--function-btn-icon-filter': this.featureEnabled.bwCamera ? 'none' : 'brightness(0) invert(1)',
        '--function-btn-text-color': this.featureEnabled.bwCamera ? '#000' : '#fff'
      }
    }
  },
  data() {
    return {
      videoUrl: '/static/videos/test.mp4', // 替换为实际的视频流地址
      zoomLevel: 1,
      lastTouchDistance: 0,
      showSettingsPanel: false,
      showControls: true,
      controlsTimer: null,
      connectionTimer: null, // 连接状态切换定时器
      currentSettingsSection: '云台相机',
      isConnected: false, // 连接状态
      // 功能开关状态
      featureEnabled: {
        colorCamera: true, // 彩色相机
        bwCamera: false, // 黑白相机
        tempMeasure: false, // 测温功能
        ptzCruise: false, // 云台巡航
        intercom: false, // 语音对讲
        spotlight: false, // 探照灯
        robotControl: false, // 机器狗控制
        broadcast: false // 广播功能
      },
      // 选中的广播内容ID
      selectedBroadcast: null,
      // 报警灯设置
      alarmLight: {
        enabled: false, // 默认关闭
        mode: 'normal', // normal, fast, slow
      },
      // 广播内容列表
      broadcastList: [
        { id: 1, content: '请保持安全距离', duration: 10 },
        { id: 2, content: '禁止进入危险区域', duration: 15 },
        { id: 3, content: '注意安全', duration: 5 }
      ],
      // 广播编辑对话框
      broadcastDialog: {
        show: false,
        isEdit: false,
        form: {
          id: null,
          content: '',
          duration: 5
        }
      },
      // 机器狗模式
      robotMode: 'manual', // auto, manual
      // 服务器设置
      serverConfig: {
        url: '',
        port: ''
      }
    }
  },
  mounted() {
    // 从本地存储加载设置
    this.loadSettings()
    // 初始化时启动自动隐藏计时器
    this.startHideControlsTimer()
    // 启动连接状态检查
    this.startConnectionCheck()
    // 监听页面显示事件
    uni.$on('page-show', this.showControlsWithDelay)
    // 离线状态下默认显示系统设置面板
    if (!this.isConnected) {
      this.currentSettingsSection = '系统'
    }
  },
  beforeDestroy() {
    // 清除计时器和事件监听
    this.clearHideControlsTimer()
    this.clearConnectionCheck()
    uni.$off('page-show', this.showControlsWithDelay)
  },
  methods: {
    // 视频流手势操作
    handleVideoTouch(e) {
      if (e.touches.length === 2) {
        const touch1 = e.touches[0]
        const touch2 = e.touches[1]
        this.lastTouchDistance = Math.sqrt(
          Math.pow(touch2.pageX - touch1.pageX, 2) +
          Math.pow(touch2.pageY - touch1.pageY, 2)
        )
      }
    },
    handleVideoZoom(e) {
      if (e.touches.length === 2) {
        const touch1 = e.touches[0]
        const touch2 = e.touches[1]
        const currentDistance = Math.sqrt(
          Math.pow(touch2.pageX - touch1.pageX, 2) +
          Math.pow(touch2.pageY - touch1.pageY, 2)
        )

        if (this.lastTouchDistance > 0) {
          if (currentDistance > this.lastTouchDistance) {
            this.zoomLevel = Math.min(this.zoomLevel + 0.1, 30)
          } else {
            this.zoomLevel = Math.max(this.zoomLevel - 0.1, 1)
          }
        }
        this.lastTouchDistance = currentDistance
      }
    },
    // 设置面板控制
    toggleSettingsPanel() {
      this.showSettingsPanel = !this.showSettingsPanel
    },
    // 机器狗控制
    startRobotMove(direction) {
      // 实现机器狗移动控制逻辑
      console.log('机器狗开始移动:', direction)
    },
    stopRobotMove() {
      // 实现机器狗停止移动逻辑
      console.log('机器狗停止移动')
    },
    // 摄像头控制
    startCameraMove(direction) {
      // 实现摄像头移动控制逻辑
      console.log('摄像头开始移动:', direction)
    },
    stopCameraMove() {
      // 实现摄像头停止移动逻辑
      console.log('摄像头停止移动')
    },

    // 停止
    // 控制面板显示隐藏相关方法
    showControlsWithDelay() {
      this.showControls = true
      this.startHideControlsTimer()
    },
    startHideControlsTimer() {
      this.clearHideControlsTimer()
      // 10秒后隐藏
      this.controlsTimer = setTimeout(() => {
        this.showControls = false
      }, 10000)
    },
    clearHideControlsTimer() {
      if (this.controlsTimer) {
        clearTimeout(this.controlsTimer)
        this.controlsTimer = null
      }
    },
    // 保存服务器配置
    saveServerConfig() {
      uni.setStorageSync('serverConfig', this.serverConfig)
      // 同步到网络请求模块
      updateHttpConfig(this.serverConfig)
    },
    // 检查网络连接状态
    async checkConnection() {
      // 检查服务器配置是否完整
      if (!this.serverConfig.url || !this.serverConfig.port) {
        this.isConnected = false;
        return;
      }
      console.log('checkConnection', this.serverConfig)
      try {
        const response = await request({
          url: '/nsrs/captcha.jpg',
          method: 'GET',
          timeout: 5000
        });
        console.log('response', response)
        this.isConnected = response.code === 0;
      } catch (error) {
        this.isConnected = false;
      }
    },
    startConnectionCheck() {
      this.checkConnection(); // 立即检查一次
      this.connectionTimer = setInterval(() => {
        this.checkConnection();
      }, 5000); // 每5秒检查一次
    },
    clearConnectionCheck() {
      if (this.connectionTimer) {
        clearInterval(this.connectionTimer);
        this.connectionTimer = null;
      }
    },
    // 从本地存储加载设置
    loadSettings() {
      // 加载服务器配置
      const savedServerConfig = uni.getStorageSync('serverConfig');
      if (savedServerConfig) {
        this.serverConfig = savedServerConfig;
        updateHttpConfig(this.serverConfig);
      }

      // 加载功能开关状态
      const savedFeatureEnabled = uni.getStorageSync('featureEnabled');
      if (savedFeatureEnabled) {
        this.featureEnabled = savedFeatureEnabled;
      }

      // 加载报警灯设置
      const savedAlarmLight = uni.getStorageSync('alarmLight');
      if (savedAlarmLight) {
        this.alarmLight = savedAlarmLight;
      } else {
        // 确保默认值被保存到本地存储
        uni.setStorageSync('alarmLight', this.alarmLight);
      }

      // 加载机器狗模式
      const savedRobotMode = uni.getStorageSync('robotMode');
      if (savedRobotMode) {
        this.robotMode = savedRobotMode;
      } else {
        // 确保默认值被保存到本地存储
        uni.setStorageSync('robotMode', this.robotMode);
      }

      // 加载选中的广播内容
      const savedSelectedBroadcast = uni.getStorageSync('selectedBroadcast');
      if (savedSelectedBroadcast) {
        this.selectedBroadcast = savedSelectedBroadcast;
      }
    },

    // 切换功能开关状态
    toggleFeature(feature) {
      // 处理彩色相机和黑白相机的互斥
      if (feature === 'colorCamera') {
        if (!this.featureEnabled.colorCamera) {
          this.featureEnabled.bwCamera = false;
          this.featureEnabled.colorCamera = true;
          this.videoUrl = '/static/videos/test.mp4';
          this.isDarkMode = true; // 彩色相机模式下使用暗色按钮
        }
        return; // 如果已经是彩色相机，不允许取消选中
      } else if (feature === 'bwCamera') {
        if (!this.featureEnabled.bwCamera) {
          this.featureEnabled.colorCamera = false;
          this.featureEnabled.bwCamera = true;
          this.videoUrl = '/static/videos/test1.mp4';
          this.isDarkMode = false; // 黑白相机模式下使用亮色按钮
        }
        return; // 如果已经是黑白相机，不允许取消选中
      }

      this.featureEnabled[feature] = !this.featureEnabled[feature];
      // 保存设置到本地存储
      uni.setStorageSync('featureEnabled', this.featureEnabled);
      console.log(`${feature}功能状态:`, this.featureEnabled[feature] ? '开启' : '关闭');
    },
    // 切换设置面板部分
    switchSettingsSection(section) {
      this.currentSettingsSection = section
      console.log('切换到设置部分:', section)
    },
    // 切换报警灯状态
    toggleAlarmLight(e) {
      this.alarmLight.enabled = e.detail.value
      // 保存设置到本地存储
      uni.setStorageSync('alarmLight', this.alarmLight)
      console.log('报警灯状态:', this.alarmLight.enabled ? '开启' : '关闭')
    },
    // 切换报警灯模式
    changeAlarmMode(mode) {
      this.alarmLight.mode = mode
      // 保存设置到本地存储
      uni.setStorageSync('alarmLight', this.alarmLight)
      console.log('报警灯模式:', this.alarmLight.mode)
    },
    // 添加新广播
    addBroadcast() {
      uni.showModal({
        title: '新增广播',
        content: '请输入广播内容',
        editable: true,
        placeholderText: '广播内容',
        confirmText: '确定',
        cancelText: '取消',
        confirmColor: '#007AFF',
        success: (res) => {
          if (res.confirm && res.content) {
            const newBroadcast = {
              id: Date.now(),
              content: res.content,
              duration: 5
            };
            this.broadcastList.push(newBroadcast);
            this.selectedBroadcast = newBroadcast.id;
            uni.showToast({
              title: '添加成功',
              icon: 'success'
            });
          }
        }
      });
    },
    // 选择广播内容
    selectBroadcast(id) {
      this.selectedBroadcast = this.selectedBroadcast === id ? null : id;
      uni.setStorageSync('selectedBroadcast', this.selectedBroadcast);
    },
    // 编辑广播
    editBroadcast(item) {
      uni.showModal({
        title: '编辑广播',
        content: '请修改广播内容',
        editable: true,
        placeholderText: '广播内容',
        value: item.content,
        confirmText: '确定',
        cancelText: '取消',
        confirmColor: '#007AFF',
        success: (res) => {
          if (res.confirm && res.content) {
            const index = this.broadcastList.findIndex(b => b.id === item.id);
            if (index !== -1) {
              this.broadcastList[index] = {
                ...item,
                content: res.content
              };
              uni.showToast({
                title: '修改成功',
                icon: 'success'
              });
            }
          }
        }
      });
    },
    // 删除广播
    deleteBroadcast(id) {
      uni.showModal({
        title: '确认删除',
        content: '是否确认删除该广播内容？',
        success: (res) => {
          if (res.confirm) {
            const index = this.broadcastList.findIndex(item => item.id === id);
            if (index !== -1) {
              this.broadcastList.splice(index, 1);
              uni.showToast({
                title: '删除成功',
                icon: 'success'
              });
            }
          }
        }
      });
    },
    // 切换机器狗模式
    changeRobotMode(mode) {
      this.robotMode = mode
      if (this.robotMode === 'auto') {
        this.featureEnabled.robotControl = false
        // 保存功能开关状态
        uni.setStorageSync('featureEnabled', this.featureEnabled)
      }
      // 保存机器狗模式
      uni.setStorageSync('robotMode', this.robotMode)
      console.log('机器狗模式:', this.robotMode)
    },
    // 从本地存储加载设置
    loadSettings() {
      const storedFeatureEnabled = uni.getStorageSync('featureEnabled')
      const storedAlarmLight = uni.getStorageSync('alarmLight')
      const storedRobotMode = uni.getStorageSync('robotMode')
      const storedServerConfig = uni.getStorageSync('serverConfig')
      if (storedFeatureEnabled) {
        this.featureEnabled = storedFeatureEnabled
      }
      if (storedAlarmLight) {
        this.alarmLight = storedAlarmLight
      }
      if (storedRobotMode) {
        this.robotMode = storedRobotMode
      }
      if (storedServerConfig) {
        this.serverConfig = storedServerConfig
        // 同步到网络请求模块
        updateHttpConfig(storedServerConfig)
      }
      console.log('功能开关状态:', this.featureEnabled)
      console.log('报警灯状态:', this.alarmLight)
      console.log('机器狗模式:', this.robotMode)
      console.log('服务器配置:', this.serverConfig)
    }
  }
}

</script>

<style lang="scss">
.main-container {
  width: 100vw;
  height: 100vh;
  background-color: #000;
  position: relative;
  overflow: hidden;
}

.offline-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;

  .offline-text {
    color: #fff;
    font-size: 24px;
    font-weight: 500;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  }
}

.video-container {
  width: 100%;
  height: 100%;
  position: relative;

  .video-stream {
    width: 100%;
    height: 100%;
    background-color: #000;
  }
}

.status-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.3));
  backdrop-filter: blur(15px);
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);

  .status-item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 20px;
    transition: all 0.3s ease;

    image {
      width: 24px;
      height: 24px;
      filter: brightness(0) invert(1);
      transition: all 0.3s ease;
      object-fit: contain;
    }
  }

  .settings-icon {
    cursor: pointer;
  }

  .connection-status {
    &.connected {
      image {
        filter: brightness(0) saturate(100%) invert(68%) sepia(74%) saturate(1362%) hue-rotate(84deg) brightness(89%) contrast(88%);
      }
    }

    &:not(.connected) {
      image {
        filter: brightness(0) saturate(100%) invert(28%) sepia(94%) saturate(7466%) hue-rotate(353deg) brightness(101%) contrast(120%);
      }
    }
  }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 199;
}

.settings-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 400px;
  height: 400px;
  background-color: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 200;
  display: flex;
  flex-direction: column;

  &.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
  }

  .panel-header {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);

    text {
      color: #fff;
      font-size: 18px;
      font-weight: 500;
    }

    .close-btn {
      width: 30px;
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;

      text {
        color: #fff;
        font-size: 24px;
      }
    }
  }

  .panel-content {
    padding: 20px;
    flex: 1;
    overflow-y: auto;

    .settings-section {
      margin-bottom: 20px;

      &.disabled {
        opacity: 0.5;
        pointer-events: none;
      }

      .setting-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 15px;
        padding: 15px;
        background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
        border-radius: 12px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        transition: all 0.3s ease;

        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
        }

        text {
          color: #fff;
          font-size: 15px;
          font-weight: 500;
        }

        .alarm-light-controls {
          display: flex;
          align-items: center;
          gap: 15px;

          .custom-switch {
            transform: scale(1.2);
          }

          .custom-picker {
            background: rgba(255, 255, 255, 0.15);
            padding: 8px 15px;
            border-radius: 8px;
            min-width: 100px;
            text-align: center;
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.1);

            text {
              font-size: 14px;
            }

            &:active {
              background: rgba(255, 255, 255, 0.2);
            }
          }
        }

        .broadcast-controls {
          display: flex;
          align-items: center;
          gap: 10px;
        }

        .section-title {
          font-size: 16px;
          font-weight: 500;
          color: #fff;
          margin-bottom: 10px;
        }

        .radio-group {
          display: flex;
          gap: 10px;

          .radio-btn {
            padding: 6px 12px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;

            &.active {
              background: rgba(64, 158, 255, 0.8);
            }

            text {
              font-size: 14px;
              color: #fff;
            }
          }
        }

        .icon-btn {
          width: 32px;
          height: 32px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: rgba(255, 255, 255, 0.1);
          border-radius: 6px;
          cursor: pointer;
          transition: all 0.3s ease;

          &:hover {
            background: rgba(255, 255, 255, 0.2);
          }

          &.add {
            background: rgba(64, 158, 255, 0.8);

            &:hover {
              background: rgba(64, 158, 255, 1);
            }
          }

          image {
            width: 18px;
            height: 18px;
            filter: brightness(0) invert(1);
          }
        }
      }

      .broadcast-list {
        max-height: 300px;
        overflow-y: auto;
        margin-top: 10px;
        padding: 0 10px;

        .broadcast-item {
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 12px 15px;
          margin-bottom: 10px;
          background: rgba(255, 255, 255, 0.1);
          border-radius: 8px;
          transition: all 0.3s ease;
          cursor: pointer;

          &:hover {
            background: rgba(255, 255, 255, 0.15);
          }

          &.selected {
            background: rgba(0, 122, 255, 0.2);
            border: 1px solid rgba(0, 122, 255, 0.5);
          }

          .broadcast-info {
            flex: 1;
            margin-right: 15px;

            .broadcast-content {
              color: #fff;
              font-size: 14px;
              line-height: 1.4;
            }
          }

          .broadcast-actions {
            display: flex;
            gap: 10px;

            .icon-btn {
              width: 32px;
              height: 32px;
              display: flex;
              align-items: center;
              justify-content: center;
              border-radius: 6px;
              background: rgba(255, 255, 255, 0.1);
              transition: all 0.3s ease;

              &:hover {
                background: rgba(255, 255, 255, 0.2);
              }

              image {
                width: 18px;
                height: 18px;
                filter: brightness(0) invert(1);
              }

              &.edit:hover {
                background: rgba(0, 122, 255, 0.2);
              }

              &.delete:hover {
                background: rgba(255, 59, 48, 0.2);
              }
            }
          }
        }

        align-items: center;
        padding: 10px;
        margin-bottom: 0;
        background: rgba(255, 255, 255, 0.08);
        border-radius: 10px;
        transition: all 0.3s ease;

        &:hover {
          background: rgba(255, 255, 255, 0.12);
        }

        .broadcast-info {
          flex: 1;
          margin-right: 15px;

          .broadcast-content {
            color: #fff;
            font-size: 14px;
            margin-bottom: 4px;
            display: block;
          }

          .broadcast-duration {
            color: rgba(255, 255, 255, 0.6);
            font-size: 12px;
          }
        }

        .broadcast-actions {
          display: flex;
          gap: 8px;

          .action-btn {
            padding: 6px 12px;
            border-radius: 6px;
            font-size: 12px;
            border: none;
            cursor: pointer;
            transition: all 0.2s ease;

            &.edit {
              background: rgba(64, 158, 255, 0.8);
              color: #fff;

              &:hover {
                background: rgba(64, 158, 255, 1);
              }
            }

            &.delete {
              background: rgba(245, 108, 108, 0.8);
              color: #fff;

              &:hover {
                background: rgba(245, 108, 108, 1);
              }
            }
          }
        }

        background: rgba(255, 255, 255, 0.08);
        border-radius: 8px;
        transition: all 0.3s ease;

        &:hover {
          background: rgba(255, 255, 255, 0.12);
        }

        .broadcast-content {
          color: #fff;
          font-size: 14px;
          flex: 1;
        }

        .broadcast-duration {
          color: rgba(255, 255, 255, 0.6);
          font-size: 12px;
          margin-left: 10px;
        }
      }
    }

    input {
      background-color: rgba(255, 255, 255, 0.1);
      border: none;
      border-radius: 4px;
      padding: 4px 8px;
      color: #fff;
      font-size: 12px;
      width: 150px;

      &::placeholder {
        color: rgba(255, 255, 255, 0.5);
      }
    }

    picker {
      background-color: rgba(255, 255, 255, 0.1);
      padding: 4px 8px;
      border-radius: 4px;
      width: 80px;
      text-align: center;

      text {
        font-size: 12px;
      }
    }
  }
}

.panel-footer {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.8);
  border-radius: 0 0 12px 12px;

  .section-btn {
    padding: 8px 15px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;

    &:hover {
      background: rgba(255, 255, 255, 0.2);
    }

    &.active {
      background: rgba(64, 158, 255, 0.8);
    }

    text {
      font-size: 14px;
      color: #fff;
    }
  }
}

.camera-functions {
  position: absolute;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  gap: 15px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  background-color: var(--camera-functions-bg);
  padding: 10px 20px;
  border-radius: 30px;
  backdrop-filter: blur(10px);
  box-shadow: var(--camera-functions-shadow);

  &.v-show {
    opacity: 1;
    visibility: visible;
  }

  .function-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px;
    background-color: var(--function-btn-bg);
    border-radius: 8px;
    cursor: pointer;
    min-width: 40px;
    transition: all 0.3s ease;
    border: 1px solid var(--function-btn-border);

    &.active {
      background-color: rgba(64, 158, 255, 0.8);
      border-color: transparent;
    }

    &:not(.active):hover {
      background-color: var(--function-btn-hover-bg);
    }

    image {
      width: 18px;
      height: 18px;
      filter: var(--function-btn-icon-filter);
    }

    text {
      color: var(--function-btn-text-color);
      font-size: 10px;
      text-align: center;
    }
  }
}

.control-pad {
  position: absolute;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;

  &.v-show {
    opacity: 1;
    pointer-events: auto;
  }

  &.robot-control {
    left: 30px;
    bottom: 60px;
  }

  &.camera-control {
    right: 30px;
    bottom: 60px;
  }

  .direction-pad {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 15px;

    .direction-row {
      display: flex;
      justify-content: center;
      gap: 60px;

      .direction-btn {
        width: 60px;
        height: 60px;
        border-radius: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px solid rgba(255, 255, 255, 0.6);
        transition: all 0.3s ease;

        &:active {
          background-color: rgba(64, 158, 255, 0.8);
          border-color: transparent;
        }

        &:not(:active):hover {
          background-color: var(--function-btn-hover-bg);
        }

        image {
          width: 30px;
          height: 30px;
          filter: var(--function-btn-icon-filter);
        }
      }
    }
  }
}

.floating-buttons {
  position: absolute;
  right: 20px;
  top: 60px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;

  &.v-show {
    opacity: 1;
    pointer-events: auto;
  }

  .function-btn {
    width: 50px;
    height: 50px;
    border-radius: 25px;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px;

    image {
      width: 24px;
      height: 24px;
      margin-bottom: 2px;
    }

    text {
      color: #fff;
      font-size: 10px;
    }

    &:active {
      background-color: rgba(255, 255, 255, 0.2);
    }
  }
}

.emergency-stop {
  &.floating {
    position: absolute;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 80px;
    border-radius: 40px;
    background-color: #ff0000;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;

    text {
      color: #fff;
      font-size: 16px;
      font-weight: bold;
    }

    &:active {
      background-color: #cc0000;
    }
  }
}
</style>